First value of the local var: 7 First value of the parameter: 7 Second value of the parameter: 100 Second value of the local var: 7
Once the value has been passed into the invoked method
(in the example, print()
)
the invoked method can use it or change it,
but the changes do not affect the caller.
But say that the invoked method needs to send a value back to the caller.
How can it do that?
Examine the following:
class SimpleClassTwo { public int twice( int x ) { return 2*x; } } class SimpleTesterTwo { public static void main ( String[] args ) { int var = 7; int result = 0; SimpleClassTwo simple = new SimpleClassTwo(); System.out.println("First value of result: " + result ); result = simple.twice( var ); System.out.println("Second value of result: " + result ); } }